package com.lb.jwitter.action;


import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationContext;
import java.util.Map; 
import org.springframework.test.context.ContextConfiguration; 
import com.lb.jwitter.service.TblQuyenChiTietService; 
import com.lb.jwitter.service.TblTaiKhoan; 
import com.opensymphony.xwork2.ActionContext; 
import com.lb.jwitter.util.ApplicationContextProvider; 
import java.util.Collection;
import java.util.ArrayList;
import java.util.List;
import com.lb.jwitter.service.ConditionReport;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import com.opensymphony.xwork2.Action; 
import com.lb.jwitter.service.TblCTDTChuyenNganh;
import com.lb.jwitter.service.TblCTDTChuyenNganhService;
import com.lb.jwitter.service.TblCTDTKhoa;
import com.lb.jwitter.service.TblCTDTKhoaService;

import com.lb.jwitter.service.TblCTDTHeDaoTao;
import com.lb.jwitter.service.TblCTDTHeDaoTaoService;

import com.lb.jwitter.service.TblCTDTKhoiNganh;
import com.lb.jwitter.service.TblCTDTKhoiNganhService;

 /** 
 * @author QUOCVIET  
 * 
 */ 


@ContextConfiguration(locations="classpath:beans.xml") 
public class TblCTDTChuyenNganhEditFormAction{
    private int pageSize; 
    public int getPageSize() {
       return pageSize;
 }

    public void setPageSize(int pageSize) { this.pageSize = pageSize; }

    private int page; 
    public int getPage() { return page; }

    public void setPage(int page) { this.page = page; }

    private int pages; 
    public int getPages() { return pages; }

    public void setPages(int pages) { this.pages = pages; }

    private int id; 
    public int getId() { return id; }

    public void setId(int id) { this.id = id; }

    private TblCTDTChuyenNganh tblCTDTChuyenNganh; 
    public TblCTDTChuyenNganh getTblCTDTChuyenNganh() { 
        return tblCTDTChuyenNganh; 
    } 
    private Collection<TblCTDTChuyenNganh> tblCTDTChuyenNganhs; 
    public Collection<TblCTDTChuyenNganh>  getTblCTDTChuyenNganhs() {
         return tblCTDTChuyenNganhs; 
      } 

    private TblCTDTChuyenNganhService tblCTDTChuyenNganhService; 

    private Collection<TblCTDTKhoa> tblCTDTKhoas; 
    public Collection<TblCTDTKhoa>  getTblCTDTKhoas(){ 
              return tblCTDTKhoas; 
     } 

    private TblCTDTKhoaService tblCTDTKhoaService; 

    private Collection<TblCTDTHeDaoTao> tblCTDTHeDaoTaos; 
    public Collection<TblCTDTHeDaoTao>  getTblCTDTHeDaoTaos(){ 
              return tblCTDTHeDaoTaos; 
     } 

    private TblCTDTHeDaoTaoService tblCTDTHeDaoTaoService; 

    private Collection<TblCTDTKhoiNganh> tblCTDTKhoiNganhs; 
    public Collection<TblCTDTKhoiNganh>  getTblCTDTKhoiNganhs(){ 
              return tblCTDTKhoiNganhs; 
     } 

    private TblCTDTKhoiNganhService tblCTDTKhoiNganhService; 

  private TblTaiKhoan taiKhoanDangNhap; 
 public TblTaiKhoan getTaiKhoanDangNhap() { 
     return taiKhoanDangNhap; 
 } 
 public void setTaiKhoanDangNhap(TblTaiKhoan taiKhoanDangNhap) { 
     this.taiKhoanDangNhap = taiKhoanDangNhap; 
 } 
 private TblQuyenChiTietService tblQuyenChiTietService;
	 @Autowired // Injected by Spring 
     ApplicationContextProvider contextProvider; 
    public String execute() throws Exception 
   { 
       try{ 
     Map session = ActionContext.getContext().getSession();
     taiKhoanDangNhap =  (TblTaiKhoan) session.get("taiKhoan");
     if( taiKhoanDangNhap == null) return "noprivilege";
    ApplicationContext context = ApplicationContextProvider.getApplicationContext(); 
    tblQuyenChiTietService = (TblQuyenChiTietService) context.getBean("tbl_Quyen_ChiTietClient"); 
    if(!tblQuyenChiTietService.checkRight(taiKhoanDangNhap.getMaNhomQuyen().getId(), "tbl_CTDT_ChuyenNganh", "sua")){ 
        return "noprivilege"; 
    }
        tblCTDTChuyenNganhService = (TblCTDTChuyenNganhService) context.getBean("tbl_CTDT_ChuyenNganhClient"); 
        tblCTDTKhoaService = (TblCTDTKhoaService) context.getBean("tbl_CTDT_KhoaClient"); 

        tblCTDTHeDaoTaoService = (TblCTDTHeDaoTaoService) context.getBean("tbl_CTDT_HeDaoTaoClient"); 

        tblCTDTKhoiNganhService = (TblCTDTKhoiNganhService) context.getBean("tbl_CTDT_KhoiNganhClient"); 

        tblCTDTChuyenNganh = tblCTDTChuyenNganhService.gettblCTDTChuyenNganh(new Long(id)); 
        tblCTDTKhoas = tblCTDTKhoaService.findAlltblCTDTKhoa(0, 0);

        tblCTDTHeDaoTaos = tblCTDTHeDaoTaoService.findAlltblCTDTHeDaoTao(0, 0);

   if (pageSize == 0) 
   { 
       pageSize = 20; 
   } 
   if (page == 0) 
   { 
       page = 1; 
   } 
   List<ConditionReport> cons = new ArrayList<ConditionReport>(); 
cons.clear(); 
   if (id != 0) 
   { 
       ConditionReport con = new ConditionReport(); 
       con.setCol("chuyenNganhId.id"); 
       con.setValue1(new Long(id)); 
       con.setOperator("eq"); 
       cons.add(con); 
   } 
   tblCTDTKhoiNganhs = tblCTDTKhoiNganhService.findtblCTDTKhoiNganhByCondition(cons, pageSize, page); 
        return Action.SUCCESS; 
      } 
      catch(Exception e){ 
      System.out.println("Loi EditForm tbl_CTDT_ChuyenNganh Action"); 
     e.printStackTrace(); 
    return Action.ERROR; 
 } 
 } 
 } 
 
